package com.cs307.redcross.client;

import java.io.Serializable;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.ToggleButton;
import com.google.gwt.user.client.ui.Grid;

public class AdminHeader extends Composite implements Serializable {
	private static final long serialVersionUID = 6894468356507740802L;
	protected ToggleButton selectedButton;
	
	public AdminHeader() {
		
		HorizontalPanel horizontalPanel = new HorizontalPanel();
		horizontalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		initWidget(horizontalPanel);
		horizontalPanel.setSize("1105px", "14px");
		
		Grid grid_2 = new Grid(1, 1);
		horizontalPanel.add(grid_2);
		grid_2.setWidth("11px");
		
		ToggleButton eventsButton = new ToggleButton("Events");
		eventsButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				
				// set the contentPanel to display the content needed
				ContentPanel.getInstance().setContent(new EventsContent());
				
				// clear the subheader
				SubheaderPanel.getInstance().clearSubheader();
				
				// untoggle the last selected button
				if (selectedButton != null)
					selectedButton.setDown(false);
					selectedButton = (ToggleButton)event.getSource();
			}
		});
		
		ToggleButton calendarButton = new ToggleButton("Calendar");
		calendarButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				
				// set the contentPanel to display the content needed
				ContentPanel.getInstance().setContent(new CalendarContent());
				
				// clear the subheader
				SubheaderPanel.getInstance().clearSubheader();
				
				// untoggle the last selected button
				if (selectedButton != null)
					selectedButton.setDown(false);;
				selectedButton = (ToggleButton)event.getSource();
			}
		});
		
		horizontalPanel.add(calendarButton);
		calendarButton.setWidth("85px");
		horizontalPanel.add(eventsButton);
		eventsButton.setWidth("85px");
		
		ToggleButton groupsButton = new ToggleButton("Groups");
		groupsButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				
				// set the contentPanel to display the content needed
				ContentPanel.getInstance().setContent(new GroupsContent());
				
				// clear the subheader
				SubheaderPanel.getInstance().clearSubheader();
				
				// untoggle the last selected button
				if (selectedButton != null)
					selectedButton.setDown(false);
				selectedButton = (ToggleButton)event.getSource();
			}
		});
		horizontalPanel.add(groupsButton);
		groupsButton.setWidth("85px");
		
		ToggleButton eventTemplatesButton = new ToggleButton("Event Templates");
		eventTemplatesButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				
				// set the contentPanel to display the content needed
				ContentPanel.getInstance().setContent(new TemplatesEventContent());

				
				// update the subheader to show the correct buttons
				SubheaderPanel.getInstance().clearSubheader();
				
				// untoggle the last selected button
				if (selectedButton != null)
					selectedButton.setDown(false);
				selectedButton = (ToggleButton)event.getSource();
			}
		});
		
		Grid grid_4 = new Grid(1, 1);
		horizontalPanel.add(grid_4);
		grid_4.setWidth("50px");
		horizontalPanel.add(eventTemplatesButton);
		eventTemplatesButton.setWidth("116px");
		
		ToggleButton usersButton = new ToggleButton("Users");
		usersButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				
				// set the contentPanel to display the content needed
				ContentPanel.getInstance().setContent(new AdminUserContent());
				
				// clear the subheader
				SubheaderPanel.getInstance().clearSubheader();
				
				// untoggle the last selected button
				if (selectedButton != null)
					selectedButton.setDown(false);
				selectedButton = (ToggleButton)event.getSource();
			}
		});
		
		ToggleButton reminderTemplates = new ToggleButton("Reminder Templates");
		reminderTemplates.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				
				// set the contentPanel to display the content needed
				ContentPanel.getInstance().setContent(new TemplatesReminderContent());
				
				// clear the subheader
				SubheaderPanel.getInstance().clearSubheader();
				
				// untoggle the last selected button
				if (selectedButton != null)
					selectedButton.setDown(false);
				selectedButton = (ToggleButton)event.getSource();
			}
		});
		horizontalPanel.add(reminderTemplates);
		reminderTemplates.setWidth("136px");
		
		Grid grid_1 = new Grid(1, 1);
		horizontalPanel.add(grid_1);
		grid_1.setWidth("50px");
		horizontalPanel.add(usersButton);
		usersButton.setWidth("85px");
		
		ToggleButton sendSMSButton = new ToggleButton("Send SMS");
		sendSMSButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				
				// set the contentPanel to display the content needed
				ContentPanel.getInstance().setContent(new SendSMSContent());
				
				// clear the subheader
				SubheaderPanel.getInstance().clearSubheader();
				
				// untoggle the last selected button
				if (selectedButton != null)
					selectedButton.setDown(false);
				selectedButton = (ToggleButton)event.getSource();
			}
		});
		
		ToggleButton myInfoButton = new ToggleButton("My Info");
		horizontalPanel.add(myInfoButton);
		myInfoButton.setWidth("85px");
		myInfoButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				
				// set the contentPanel to display the content needed
				ContentPanel.getInstance().setContent(new MyInfoContent());
				
				// clear the subheader
				SubheaderPanel.getInstance().clearSubheader();
				
				// untoggle the last selected button
				if (selectedButton != null)
					selectedButton.setDown(false);
				selectedButton = (ToggleButton)event.getSource();
			}
		});
		
		Grid grid_3 = new Grid(1, 1);
		horizontalPanel.add(grid_3);
		grid_3.setWidth("50px");
		
		ToggleButton activityLogsButton = new ToggleButton("Activity Logs");
		activityLogsButton.setVisible(false);
		activityLogsButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				
				// set the contentPanel to display the content needed
				ContentPanel.getInstance().setContent(new ActivityLogsContent());
				
				// clear the subheader
				SubheaderPanel.getInstance().clearSubheader();
				
				// untoggle the last selected button
				if (selectedButton != null)
					selectedButton.setDown(false);
				selectedButton = (ToggleButton)event.getSource();
			}
		});
		horizontalPanel.add(activityLogsButton);
		activityLogsButton.setWidth("85px");
		horizontalPanel.add(sendSMSButton);
		sendSMSButton.setWidth("85px");
	}
	
}
